﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Xml;
using System.IO;

namespace YXShop.Web.admin.templates.label
{
    public partial class selectlabelclass : System.Web.UI.Page
    {
        public string labelclass = "";
        public string labelname = "";
        protected string FileName = "";
        protected string FilePath = "";
        protected string styleId = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (ChangeHope.WebPage.PageRequest.GetString("LT") != string.Empty)
            {
                 styleId = ChangeHope.WebPage.PageRequest.GetString("StyleId");
                 labelclass = ChangeHope.WebPage.PageRequest.GetString("LT");
                 labelname = ChangeHope.WebPage.PageRequest.GetQueryString("LN");
                 FileName = ChangeHope.WebPage.PageRequest.GetString("FileName");
                 FilePath = ChangeHope.WebPage.PageRequest.GetString("FilePath");
                switch (labelclass)
                {
                    case "YXShopDefinTag":
                        string templatePath = ChangeHope.WebPage.PageRequest.GetQueryString("FilePath");
                        int pCount = templatePath.IndexOf('/', 26);
                        if (pCount > 0)
                        {
                            templatePath = templatePath.Substring(0, pCount);
                        }
                        string path = Server.MapPath("~//" + templatePath + "/label/label.xml");
                        if (File.Exists(path))
                        {
                            XmlDocument xmlDoc = new XmlDocument();
                            xmlDoc.Load(path);
                            XmlNodeList nodeLists = xmlDoc.SelectSingleNode("templetelabel").ChildNodes;//获取label节点的所有子节点
                            foreach (XmlNode xn in nodeLists)//遍历所有子节点
                            {
                                XmlElement xe = (XmlElement)xn;//将子节点类型转换为XmlElement类型
                                string labelNameXML = xe.GetAttribute("Name");
                                if (labelNameXML == labelname)
                                {
                                    XmlNodeList nls = xe.ChildNodes;//继续获取xe子节点的所有子节点
                                    string moduleId = string.Empty;
                                    string labeltype = string.Empty;
                                    foreach (XmlNode xn1 in nls)//遍历
                                    {
                                        XmlElement xe2 = (XmlElement)xn1;//转换类型
                                        if (xe2.Name == "moduleid")//如果找到
                                        {
                                            moduleId = xe2.InnerText;
                                            continue;//找到后继续
                                        }
                                        if (xe2.Name == "labeltype")//如果找到
                                        {
                                            labeltype = xe2.InnerText;
                                            continue;//找到后继续
                                        }

                                    }
                                    Response.Redirect("label_edit.aspx?moduleid=" + moduleId + "&name=" + labelname + "&tid=" + labeltype + "&FileName=" + FileName + "&FilePath=" + FilePath + "&StyleId=" + styleId + "");
                                }
                            }


                            //YXShop.BLL.Templates.Label bll = new YXShop.BLL.Templates.Label();
                            //YXShop.Model.Templates.Label model = bll.GetModelName(labelname);
                            //if (model != null)
                            //{
                            //    Response.Redirect("label_edit.aspx?moduleid=" + model.Moduleid + "&name=" + labelname + "&tid=" + model.TID + "&FileName=" + FileName + "&FilePath=" + FilePath + "&StyleId=" + styleId + "");
                            //}
                        }
                        break;
                    //case "YXShopFreeTag":
                    //    YXShop.BLL.FreeLabel fb = new YXShop.BLL.FreeLabel();
                    //    List<YXShop.Model.FreeLabelInfo> datafl = fb.GetListByColumn("L_Name", Request["LN"].ToString());
                    //    YXShop.Model.FreeLabelInfo mlbfl = new YXShop.Model.FreeLabelInfo();
                    //    if (datafl.Count > 0)
                    //    {
                    //        Lt = Request["LT"].ToString();
                    //        ln = Request["LN"].ToString();
                    //        Response.Redirect("../FreeLabel_Add.aspx?LT=" + Lt + "&LN=" + ln + "&type=0&ty=" + datafl[0].L_LabelType.ToString());
                    //    }
                    //    else
                    //    {
                    //        //用户在模版里设置的标签名 --》修改
                    //        Lt = Request["LT"].ToString();
                    //        ln = Request["LN"].ToString();
                    //        Response.Redirect("../FreeLabel_Add.aspx?LT=" + Lt + "&LN=" + ln + "&type=0&pe=2");
                    //    }
                    //    break;
                    default:
                        break;
                }
            }
        }
    }
}
